﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class LicensePanel : MonoBehaviour
{
    public Text m_Title;
    public Text m_Description;


    public Text m_MoveExamProcess;
    public Text m_ShotExamProcess;
    public Text m_RealFightExmanProcess;

    public LicenseBook m_LicenseBook;
    public SceneSwiter m_SceneSwiter;
    public Button m_NormalLicenseB;
    public Button m_GoodLicenseB;
    public Button m_PerfactLicenseB;
    public AudioSource m_Warning;

    Driver.DriveLevel m_SelectLevel;
    string m_MoveExamination;
    string m_ShotExamination;
    string m_RealFightExamination;

    public GameObject m_PassD;
    public GameObject m_PassC;
    public GameObject m_PassB;
    public GameObject m_PassA;
    public GameObject m_PassAP;
    public List<GameObject> m_PassList = new List<GameObject>();
    private void Awake()
    {
        m_PassList.Add(m_PassAP);
        m_PassList.Add(m_PassA);
        m_PassList.Add(m_PassB);
        m_PassList.Add(m_PassC);
        m_PassList.Add(m_PassD);
    }
    void Start()
    {
        for (int i = 0; i < m_PassList.Count; ++i)
        {
            if (m_PassList[i])
            {
                m_PassList[i].SetActive(false);
            }
        }
        for (int i = (int)Driver.DriveLevel.LEVEL_D; i >= (int)Player.Instance.m_DriveLevel; --i)
        {
            if (m_PassList[i])
            {
                m_PassList[i].SetActive(true);
            }
        }
        OnLicenseDClicked();
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    void UpdateProcess(Driver.DriveLevel level)
    {
        m_NormalLicenseB.gameObject.SetActive(false);
        m_GoodLicenseB.gameObject.SetActive(false);
        m_PerfactLicenseB.gameObject.SetActive(false);

        List<Text> examProcess = new List<Text>();
        examProcess.Add(m_MoveExamProcess);
        examProcess.Add(m_ShotExamProcess);
        examProcess.Add(m_RealFightExmanProcess);

        for (int i=0; i< Player.EXAMINATION_NUMBER; ++i)
        {
            switch((Driver.LicenseEvaluate)Player.Instance.DriveLicenseState[(int)level, i])
            {
                case Driver.LicenseEvaluate.NOT_PASS:
                    examProcess[i].text = "";
                    break;
                case Driver.LicenseEvaluate.PASS:
                    examProcess[i].text = "已完成";
                    examProcess[i].color = new Vector4(0, 1, 0, 1);
                    break;
                case Driver.LicenseEvaluate.NIU_BI:
                    examProcess[i].text = "已牛逼的完成";
                    examProcess[i].color = new Vector4(1, 0, 1, 1);
                    break;
            }
        }

        int weight = Player.Instance.DriveLicenseState[(int)level, 0] * Player.Instance.DriveLicenseState[(int)level, 1] * Player.Instance.DriveLicenseState[(int)level, 2];

        if(weight == 1)
            m_NormalLicenseB.gameObject.SetActive(true);
        else if(weight > 1 && weight < 9)
            m_GoodLicenseB.gameObject.SetActive(true);
        else if(weight >= 9)
            m_PerfactLicenseB.gameObject.SetActive(true);
    }

    public void OnLicenseDClicked()
    {
        m_SelectLevel = Driver.DriveLevel.LEVEL_D;
        m_Title.text = "D级驾驶许可考试";
        m_Description.text = "本次考试的主要内容集中在基础训练，目标是让驾驶员掌握基础的移动、射击能力。完成考核的驾驶员学院会为其办法D级驾驶许可证，该证书拥有驾驶护卫舰的权力。" +
            "\n- 移动能力考核主要在基本的前进和拐弯上，所以考试设计了一条90度的赛道，经过大量测试90%新生完成测试后在战场上表现优异。" +
            "\n- 设计能力考核还是单纯的打靶训练。主要为了让驾驶员掌握射击的手感。以及理解攻击目标的选择" +
            "\n- 最后是实战训练，为了让驾驶员在战场上有基本的生存能力，我校特意从不明渠道搞到了大量的比特级，来作为各个新手驾驶员的最后测试。最后，祝各位考生顺利。";

        m_MoveExamination = "MoveExaminationD";
        m_ShotExamination = "ShotExaminationD";
        m_RealFightExamination = "RealFightExaminationD";

        UpdateProcess(m_SelectLevel);
    }
    public void OnLicenseCClicked()
    {
        if(Player.Instance.m_DriveLevel > Driver.DriveLevel.LEVEL_D)
        {
            MessageShow.Instance.Messaage("先去看看D级吧。");
            if(m_Warning)
                m_Warning.Play();
            return;
        }

        m_SelectLevel = Driver.DriveLevel.LEVEL_C;
        m_Title.text = "C级驾驶许可考试";
        m_Description.text = "" +
            "C级战舰有动力强，火力足的优点，属于中小型舰体。其中该级的舰体最普遍的就是应用在小型货舰上，本次考核的目标就是小型货舰(艾米驴)级" +
            "\n- 移动能力考核：主要考核学员的拉货能力，艾米驴级在战场打捞队中最为普及，学员应学会如何驾驶艾米驴级在战场中生存下去。" +
            "\n- 射击能力考核：C级战舰的最大优点体现在初步开始装备中型武器，本次考核的目标是合理使用中型武器击败高级敌方单位。" +
            "\n- 最后是实战：C级战舰的火力往往高于D级战舰，本次实战是一对三的模式。当学院掌握了同时对付多架舰体时，战场上自然也是游刃有余。";

        m_MoveExamination = "MoveExaminationC";
        m_ShotExamination = "ShotExaminationC";
        m_RealFightExamination = "RealFightExaminationC";

        UpdateProcess(m_SelectLevel);
    }
    public void OnLicenseBClicked()
    {
        if (Player.Instance.m_DriveLevel > Driver.DriveLevel.LEVEL_C)
        {
            MessageShow.Instance.Messaage("先去看看C级吧。");
            if (m_Warning)
                m_Warning.Play();
            return;
        }

        m_SelectLevel = Driver.DriveLevel.LEVEL_B;
        m_Title.text = "B级驾驶许可考试";
        m_Description.text = "" +
            "B级战舰是中大型战舰，在战场上往往作为主要火力输出。许多B级战舰都发挥了该等级战舰体型大的优势配备了大型武器槽。B级战舰的缺点也很明显，太慢了，本次考核的目的是让驾驶员学会如何使用B级战舰在战场发挥作用，驾驶员需要熟练使用“英灵殿”级在战场上发挥作用。" +
            "\n- 移动能力考核：移动考核的主要内容集中在大型舰体的缓慢移动和惯性控制上，习惯了小型舰体的驾驶员需要加强训练，导弹可不长眼睛。" +
            "\n- 射击能力考核：射击考核主要是让学员熟悉B级舰体特有的母舰的基本操作，熟悉待机、出击、回收等驾驶员命令，对目标进行有效打击。" +
            "\n- 最后是实战：母舰在战场中很难独自生存下去，缺乏近防火力网让导弹有机可乘，缺乏普遍的武器槽让他很难和大型战舰对拼火。硬抗不是母舰的策略，一边后退，然后逐个击破敌人吧。";

        m_MoveExamination = "MoveExaminationB";
        m_ShotExamination = "ShotExaminationB";
        m_RealFightExamination = "RealFightExaminationB";

        UpdateProcess(m_SelectLevel);
    }
    public void OnLicenseAClicked()
    {

    }
    public void OnLicenseAPClicked()
    {

    }


    public void OnMoveExaminationStart()
    {
        m_SceneSwiter.switchScene(m_MoveExamination);
    }
    public void OnShotExamninationStart()
    {
        if((Driver.LicenseEvaluate)Player.Instance.DriveLicenseState[(int)m_SelectLevel, 0] == Driver.LicenseEvaluate.NOT_PASS)
        {
            MessageShow.Instance.Messaage("请先完成移动考核");
            return;
        }
        m_SceneSwiter.switchScene(m_ShotExamination);
    }
    public void OnRealFightExaminationStart()
    {
        if ((Driver.LicenseEvaluate)Player.Instance.DriveLicenseState[(int)m_SelectLevel, 1] == Driver.LicenseEvaluate.NOT_PASS)
        {
            MessageShow.Instance.Messaage("请先完成移动考核和射击考核");
            return;
        }
        m_SceneSwiter.switchScene(m_RealFightExamination);
    }

    public void OnLicenseBookShow()
    {
        m_LicenseBook.gameObject.SetActive(true);
        m_LicenseBook.Level = m_SelectLevel;


    }
}
